package com.yty.myadmin.config.mybatis;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;

import java.beans.PropertyVetoException;

@Configuration
@PropertySource("classpath:dbconfig/admindbconfig.yaml")
public class DBConfigure {

    @Autowired
    private Environment env;

    @Bean(name="adminDB")
    public DruidDataSource druidDataSource() throws PropertyVetoException{
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName(env.getProperty("driverClassName"));
        dataSource.setUrl(env.getProperty("url"));
        dataSource.setUsername(env.getProperty("name"));
        dataSource.setPassword(env.getProperty("password"));
        dataSource.setMaxActive(20);
        dataSource.setMinIdle(1);
        dataSource.setInitialSize(5);
        dataSource.setMaxWait(300);
        dataSource.setTimeBetweenEvictionRunsMillis(6000);
        dataSource.setKeepAlive(true);
        return dataSource;
    }
}
